class CategoriesController < ApplicationController
	def new
		@category=InfoCategory.new
	end
	def create
		@category=InfoCategory.new(category_params)
		if @category.save
			MyMailer.welcome_email.deliver
			redirect_to categories_path
		else
			render 'new'
		end
	end

	def index
		@categories=InfoCategory.all
	end

	def add
		@id=params[:id]
		@category=InfoCategory.new()
	end
	def build
		category=InfoCategory.new(builde_params)
		if category.save
			redirect_to categories_path
		else
			render 'add'
		end
	end

	def destroy
		InfoCategory.find(params[:id]).delete
		redirect_to categories_path
	end

	def edit
		@category=InfoCategory.find(params[:id])

	end

	private
	def category_params
		params.require(:info_category).permit(:name)
	end
	def builde_params
		params.require(:info_category).permit(:name,:parent_id)
	end
end
